package com.stf.dialoglibrary;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class DialogManager {

    private static DialogManager dialogManager;
    private boolean isVisCanTv = false;
    private boolean isToast = false;
    private int day = 3;

    public static DialogManager getInstance() {
        if (dialogManager == null) {
            synchronized (CalendarUtil.class) {
                if (dialogManager == null) {
                    dialogManager = new DialogManager();
                }
            }
        }
        return dialogManager;
    }

    public DialogManager setVisCanTv(boolean isVisCanTv) {
        this.isVisCanTv = isVisCanTv;
        return dialogManager;
    }

    public DialogManager setIsShowToast(boolean isToast) {
        this.isToast = isToast;
        return dialogManager;
    }

    public DialogManager setAddDay(int day) {
        this.day = day;
        return dialogManager;
    }

    public void showDialog(Activity activity, View parent_view) {
        Log.i("hx", "--isShowDialog--->" + isShowDialog(activity));
        if (isShowDialog(activity)) {
            DiaogUtil.showTipDialog(activity, parent_view, day, isVisCanTv, new DiaogUtil.OnNickNameLisenter() {
                @Override
                public void OnOkBtn(String msg, PopWindowUtils popWindow) {
                    Log.i("hx", "--showTipDialog--最新的时间->" + SharedNoClearUtil.create(activity).getString(SharedConfig.initTime));
                    if(isToast){
                        MyToast.show(activity, "最新的时间" + SharedNoClearUtil.create(activity).getString(SharedConfig.initTime));
                    }
                }
            });
        } else {
            if(isToast){
                MyToast.show(activity, "时间" + SharedNoClearUtil.create(activity).getString(SharedConfig.initTime,SharedConfig.initTimeValue) + "不需要弹框");
            }
        }
    }

    public void showDialog(Activity activity, View parent_view, String msg, OnOkBtnLisenter lisenter) {
        if (isShowDialog(activity)) {
            DiaogUtil.showTipDialog(activity, parent_view, day, isVisCanTv, new DiaogUtil.OnNickNameLisenter() {
                @Override
                public void OnOkBtn(String msg, PopWindowUtils popWindow) {
                    Log.i("hx", "--showTipDialog--最新的时间->" + SharedNoClearUtil.create(activity).getString(SharedConfig.initTime));
                    if(isToast){
                        MyToast.show(activity, "最新的时间" + SharedNoClearUtil.create(activity).getString(SharedConfig.initTime));
                    }
                    lisenter.OnOkBtn(msg, popWindow);
                }
            });
        }else {
            if(isToast){
                MyToast.show(activity, "时间" + SharedNoClearUtil.create(activity).getString(SharedConfig.initTime,SharedConfig.initTimeValue) + "不需要弹框");
            }
        }
    }


    private boolean isShowDialog(Context context) {
        CalendarUtil calendarUtil = new CalendarUtil();
        String ymdNew = calendarUtil.getYMD();
        String ymdOld = SharedNoClearUtil.create(context).getString(SharedConfig.initTime, SharedConfig.initTimeValue);
        int i = calendarUtil.timeCompareYMD(ymdOld, ymdNew);
        Log.i("hx", "-i-->" + i + "--ymdNew->" + ymdNew + "--ymdOld-->" + ymdOld);
        if (i <= 0) {
            return true;
        } else {
            return false;
        }
    }

    public interface OnOkBtnLisenter {
        void OnOkBtn(String msg, PopWindowUtils popWindow);
    }
}
